package com.example.mapping.mapper;

import com.example.mapping.domain.ColumnMetadata;
import com.example.mapping.domain.TableMetadata;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 表mapper
 *
 * @author baoyoujia
 */
public interface TableMapper {

    /**
     * 获取所有的表
     * @return 表名
     */
    @Select("select TABLE_NAME as tableName, TABLE_COMMENT as tableComment from information_schema.TABLES where TABLE_SCHEMA=(select database())")
    List<TableMetadata> tableList();

    /**
     * 获取指定表的表名
     * @param tableName 表名
     * @return 列信息
     */
    @Select("select COLUMN_NAME as columnName, DATA_TYPE as dataType, ORDINAL_POSITION as ordinalPosition, IS_NULLABLE as isNullable, COLUMN_TYPE as columnType, COLUMN_COMMENT as columnComment from information_schema.COLUMNS where TABLE_SCHEMA = (select database()) and TABLE_NAME = #{tableName}")
    List<ColumnMetadata> tableColumnList(String tableName);
}
